import request from '@/utils/request'

//根据用户名查询用户信息（唯一）
export function getByUsername(username) {
  return request({
    url: `/user/getByUsername/${username}`,
    method: 'get',
  })
}

//判断验证码是否正确
export function emailCodeRight(email, code) {
  return request({
    url: `/user/emailCodeRight/${email}/${code}`,
    method: 'get',
  })
}

//修改个人信息
export function saveInfo(userInfo) {
  return request({
    url: `/user/saveInfo`,
    method: 'post',
    data: userInfo
  })
}

//修改密码
export function forgerPassword(loginForm) {
  return request({
    url: `/user/forgetPassword`,
    method: 'post',
    data: loginForm
  })
}

// 注册
export function register(loginForm) {
  return request({
    url: `/user/register`,
    method: 'post',
    data: loginForm
  })
}

// 发送验证码
export function sendCode(email) {
  return request({
    //注意用飘号
    url: `/user/register/sendCode/${email}`,
    method: 'get'
  })
}
//登录
export function login(data) {
  return request({
    url: '/user/login',
    method: 'post',
    data
  })
}
//获取用户信息
export function getInfo(token) {
  return request({
    url: '/user/info',
    method: 'get',
    params: { token }
  })
}
//登出
export function logout(token) {
  return request({
    url: '/user/logout',
    method: 'post',
    params: { token }
  })
}
